jQuery(function($){
  $("button.js-todo-finish-list").on("click", function(){
    var finishedList = JST['ruiqu/todos/finished_list']
    $.ajax({
      url: "/api/todos/finished",
      method: "get",
      success: function(data){
        $("ul#todo-list form").html(finishedList(data))
        getTodoCheckedLength();
      }
    })
  }); //end finished list todo


  $("button.js-todo-unfinish-list").on("click", function(){
    var unfinishedList = JST['ruiqu/todos/unfinished_list']
    $.ajax({
      url: "/api/todos",
      method: "get",
      success: function(data){
        $("ul#todo-list form").html(unfinishedList(data))
        getTodoCheckedLength()
      }
    })
  }); //end unfinished list todo


  $("button.js-todo-all-list").on("click", function(){
    var list = JST['ruiqu/todos/list']
    $.ajax({
      url: "/api/todos/list",
      method: "get",
      success: function(data){
        $("ul#todo-list form").html(list(data))
        getTodoCheckedLength()
      }
    })
  }); //end all list todo


  $("div#todo-app a.js-clear-todo").on("click", function(){
    BootstrapDialog.confirm('确定删除这些任务吗？', function(result){
      if(result){
        var formdata = $("ul#todo-list form").serializeJSON();
        var csrf = $("input#js-todo-index-csrf").val();
        var ids = formdata.ids
        $.ajax({
          url: "/api/todos/delete",
          method: 'delete',
          headers: {
    				'X-CSRF-Token': csrf
    			},
          data: {ids: ids},
          success: function(data){
            if(data.status == true){
              ids.forEach(function(item){
                $("li#js-todo-li-"+ item).remove();
                $("a.js-clear-todo").hide();
              })
            }
          }
        })
      }
    })
  }) // end delete some checked todo

});
